package com.jason.bbs.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jason.bbs.bean.UserInfo;
import com.jason.bbs.service.UserInfoService;

@Controller
public class UserController {
	@Resource
	private UserInfoService userInfoService;

	@GetMapping("/login")
	public String login() {
		return "login";
	}

	@PostMapping("/login")
	@ResponseBody
	public Object login(UserInfo userInfo, HttpSession session) {
		Map<String, Object> rs = new HashMap<>();
		userInfo = userInfoService.login(userInfo);
		if (userInfo == null) {
			rs.put("errorMsg", "用户名或密码错误");
		}
		return rs;
	}
}
